package com.business.systemmanage.controller;


import com.business.systemmanage.common.entity.ResponseInfo;
import com.business.systemmanage.entity.MemberLevel;
import com.business.systemmanage.service.IMemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 会员等级 前端控制器
 * </p>
 *
 * @author sixDog
 * @since 2019-04-12
 */
@Api(value = "会员等级", description = "会员等级API")

@RestController
@RequestMapping("/systemmanage/member-level")
public class MemberLevelController {
    @Autowired
    private IMemberLevelService iMemberLevelService;

    @ApiOperation(
            value = "根据会员id获取会员信息",
            notes = "会员id要填写整数哦",
            tags = {"会员"})
    @ApiImplicitParam(paramType = "query", name = "id", value = "id", required = true, dataType = "Long")
    @RequestMapping("/find")
    public ResponseInfo find(@RequestParam Long id) {
        try {
            MemberLevel memberLevel = iMemberLevelService.getById(id);
            return ResponseInfo.generateObjectRes(memberLevel);
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }

    @ApiOperation(
            value = "保存会员信息",
            notes = "插入会员id不要填写",
            tags = {"会员"})
    @RequestMapping("/save")
    public ResponseInfo save(@RequestBody MemberLevel memberLevel) {
        try {
            iMemberLevelService.save(memberLevel);
            return ResponseInfo.generateSuccessRes();
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }
}
